<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */

    $page_current['title'] 				= isset($page_current['title']) ? $page_current['title'] : "";
    $page_current['page_title'] 		= isset($page_current['page_title']) ? $page_current['page_title'] : "";
    $page_current['meta_keywords'] 		= isset($page_current['meta_keywords']) ? $page_current['meta_keywords'] : "";
    $page_current['meta_description'] 	= isset($page_current['meta_description']) ? $page_current['meta_description'] : "";
    $page_current['content'] 			= isset($page_current['content']) ? $page_current['content'] : "";
	$page_current['hook'] 				= isset($page_current['hook']) ? $page_current['hook'] : "";
	$page_current['rendertype'] 			= isset($page_current['rendertype']) ? $page_current['rendertype'] : "";

	$Html = App::load("Helper/Html");

	//---------------------------------------------------
	$themeInfo = app::__def()->getThemeInfo($this->theme);
	$hookDD = $this->__('OPTIONAL') . " <select name=\"data[Page][hook]\" >";
	$hookDD .= "<option value=\"\">Off Auto Render</option>";
	if($page_current['hook'] == 'sitemenu') $hookDD .= "<option selected=\"selected\" value=\"sitemenu\">Site Menu</option>";
	else $hookDD .= "<option value=\"sitemenu\">Site Menu</option>";

	foreach($themeInfo['hooks'] as $hook)
	{
		$hookDD .= "<optgroup label=\"{$hook['title']}\">";
		foreach($hook['list'] as $value=>$title)
		{
			if($page_current['hook'] == $value)$hookDD .= "<option selected=\"selected\" value=\"{$value}\">{$title}</option>";
			else $hookDD .= "<option value=\"{$value}\">{$title}</option>";
		}
		$hookDD .= "</optgroup>";
	}
	$hookDD .= "</select> ";

	$hookDD .= $Html->selectTag('data[Page][rendertype]',array(''=>'Render Type','h_link'=>'Link','smart_h_link'=>'Smart Link','text'=>'Text'),$page_current['rendertype']);
	//---------------------------------------------------


    /*  Calling validation 	 */
    echo App::Load("Helper/Javascript")->validation_map(array('_errBg'=>ERROR_BACKGROUND,'_dflBg'=>"#CECECE",'_autoSubmit'=>'true','_errorMark'=>'inline','_errToolTips'=>'false'));

    if( $action == 'create'):
        echo $this->get_tag("form",array("action"=>$this->baseurl("/page/manage/{$action}"),"class"=>"app_form app_validation","method"=>"post"));
    else:
        echo $this->get_tag("form",array("action"=>$this->baseurl("/page/manage/{$action}/{$page_id}"),"class"=>"app_form","id"=>"auto_chk_submit","method"=>"post"));
    endif;

    App::Helper('Toolbar')->setTitle("Static page manager")->setBtnSave()->setBtnDelete()->setBtnfileManager();
    if(isset($page_id) && isset($static_page_arr[$page_id]))
    {
        App::Helper('Toolbar')->setBtnCustomHtml(App::Helper("Html")->ButtonTag("Button[View][Page]","View Page",array("onclick"=>"document.location='" . $this->baseurl("/page/view/{$static_page_arr[$page_id]}") . "';")));
    }

    App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'static_page_save_top',"page"=>$page_current));

        echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => $errors));

        $Grid = App::Module('DataGrid')->setDisplay('FormListing');
        if( $action == 'create'):
            $Grid->addRow("Page Name",$Html->inputTag('data[Page][name]', "",array("class" => "app_input check_notempty","id" => "page_name")));
        else:
        	$Grid->addRow("Select Page",$Html->selectTag('data[Page][id]', $static_page_arr,$page_id,array("id" => "page_id","style"=>"width:200px")) . "<div style=\"float:right\"> {$hookDD}</div>");
        endif;

        if( $this->get_config('disable_page_meta_options') != "Yes"):
            $Grid->addRow("Page Meta Title",$Html->textareaTag('data[Page][page_title]', $page_current['page_title'],array("class" => "app_input","id" => "page_title")))
                 ->addRow("Meta Keywords",$Html->textareaTag('data[Page][meta_keywords]', $page_current['meta_keywords'],array("class" => "app_input","id" => "meta_keywords")))
                 ->addRow("Meta Descriptions",$Html->textareaTag('data[Page][meta_description]', $page_current['meta_description'],array("style"=>"overflow:none","class" => "app_input","id" => "meta_description")));
        endif;
        $Grid->addRow("Title",$Html->inputTag('data[Page][title]', $page_current['title'],array("class" => "app_input","id" => "title")))
             ->addRow("Content",$Html->textareaTag('data[Page][content]', $page_current['content'],array("rows" => "32","class" => "app_input richtexteditor","id" => "page_content")))
             ->render();

    /*Call the tools bar*/
    App::Helper('Toolbar')->setBtnSave()->setBtnBack()->Render(array('code'=>'static_page_save_bottom',"page"=>$page_current));
echo $this->get_tag("/form");
if( $action != 'create'):
echo "<script type=\"text/javascript\">
    window.addEvent('domready', function()
    {
        $('page_id').addEvent('change', function()
        {
            if( this.value != '')
            {
                window.location = base + '/page/manage/update/' + this.value;
            }
        });
    });
</script>";
endif;
